/*
 * interrupt.c
 *
 *  Created on: 23/dic/2013
 *      Author: massimo
 */

#include <msp430x552x.h>

/// service interrupt routine

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
  switch(__even_in_range(UCA1IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA1IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA1TXBUF = UCA1RXBUF;                  // TX -> RXed character
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}


unsigned char spiBuffer[16], TX_PTR = 0, RX_PTR = 0;
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
  switch(__even_in_range(UCA1IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    /*while (!(UCA1IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA1TXBUF = UCA1RXBUF;                  // TX -> RXed character*/
	  spiBuffer[TX_PTR++] = UCA1RXBUF;
	  TX_PTR &= 0xF;

    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}

volatile unsigned int contatore = 0;


volatile unsigned int tempoLocale = 0;
// Timer1 A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{

	//P1OUT ^= 1;
	contatore++;
	/// solo per scopi di debug e test
	tempoLocale++;
	if (tempoLocale == 50){
		tempoLocale = 0;
		TX_PTR++;
		TX_PTR &= 15;
	}

}

